package com.insurance.service.impl;

import com.insurance.common.Contants;
import com.insurance.common.ResultData;
import com.insurance.mapper.LoginRegisterMapper;
import com.insurance.service.LoginRegisterService;
import com.insurance.utils.PasswordEncryption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: 朱雄
 * Date: 2020/10/26 17:42
 * Description:
 * Version: V1.0
 */
@Service
public class LoginRegisterServiceImpl implements LoginRegisterService {

    @Autowired
    private  LoginRegisterMapper loginRegisterMapper;
    @Override
    public ResultData forgetPassword(String user_phone, String user_pwd) {
       ResultData resultData=new ResultData();
          int i=  loginRegisterMapper.updatePasswordByPhone(user_phone, PasswordEncryption.passwordEncryption(user_pwd));
        if (i>0){
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("修改成功");
                }
        return resultData;
    }

    @Override
    public Map queryByUserPhone(String user_phone){
        Map map=loginRegisterMapper.queryByUserPhone(user_phone);
        return map;
    }

    @Override
    public List<Map> queryInfoAll(String user_phone) {
        List<Map> list=loginRegisterMapper.queryInfoAll(user_phone);
        String[] str=loginRegisterMapper.queryMenuByUserPhoen(user_phone);
        for(Map map:list){
            map.put("menu",str);
        }
        return list;
    }

    @Override
    public void updateUserLastTime(String user_phone) {
        loginRegisterMapper.updateUserLastTime(user_phone);
    }

}
